# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=kvazaar
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.1
pkgrel=1
pkgdesc="An open-source HEVC encoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://ultravideo.fi/kvazaar.html"
msys2_repository_url="https://github.com/ultravideo/kvazaar"
license=("spdx:BSD-3-Clause")
depends=("${MINGW_PACKAGE_PREFIX}-crypto++"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/ultravideo/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-clang-pthread-fix.patch")
sha256sums=('c5a1699d0bd50bc6bdba485b3438a5681a43d7b2c4fd6311a144740bfa59c9cc'
            '953c0be5390b235c69e388e224c62b0d3f0e3a1b5ca3f97748c16fc3fbaa53b7')

prepare(){
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-clang-pthread-fix.patch

  autoreconf -fiv
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} build-${MSYSTEM} && cd build-${MSYSTEM}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-largefile \
    --with-cryptopp

  make
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install

  # fix .pc file
  sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}.pc"

  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
